#include "RelOp.h"

void SelectFile::Run(DBFile &inFile, Pipe &outPipe, CNF &selOp, Record &literal){

    in = &inFile;
    out = &outPipe;
    cnf = &selOp;
    buffer = &literal;

    pthread_create(&thread, NULL, SelectFileWorker, (void*)this);
}

void SelectFile::WaitUntilDone(){
    pthread_join(thread, NULL);
}

void SelectFile::Use_n_Pages(int n){
    nOfPages = n;
}

void SelectFile::DoWork(){
    Record temp;
	in->MoveFirst();

	while(in->GetNext(temp, *(cnf), *(buffer)))
        out->Insert(&temp);

    out->ShutDown();
}

void *SelectFileWorker(void *param){
     SelectFile selectFile = *((SelectFile*) param);
     selectFile.DoWork();
}
